home *** CD-ROM | disk | FTP | other *** search
/ Revista do CD-ROM 101 / CD-ROM 101.iso / compl / maya5ple / Install_MayaPLE5_English.exe / Maya / Data1.cab / initChannelBox.mel < prev    next >
Encoding:
Text File  |  2003-07-17  |  11.0 KB  |  424 lines

  1. // Copyright (C) 1997-2002 Alias|Wavefront,
  2. // a division of Silicon Graphics Limited.
  3. //
  4. // The information in this file is provided for the exclusive use of the
  5. // licensees of Alias|Wavefront.  Such users have the right to use, modify,
  6. // and incorporate this code into other products for purposes authorized
  7. // by the Alias|Wavefront license agreement, without fee.
  8. //
  9. // ALIAS|WAVEFRONT DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
  10. // INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
  11. // EVENT SHALL ALIAS|WAVEFRONT BE LIABLE FOR ANY SPECIAL, INDIRECT OR
  12. // CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
  13. // DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
  14. // TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
  15. // PERFORMANCE OF THIS SOFTWARE.
  16. //
  17. //
  18. //  Alias|Wavefront Script File
  19. //  MODIFY THIS AT YOUR OWN RISK
  20. //
  21. //  Creation Date:  19 June 1997
  22. //  Author:         bwk
  23. //
  24. //  Description:
  25. //      This script initializes the Channel box.  Initialization involves
  26. //        determining the initial Channel box preferences, creating the UI
  27. //        and setting the initial visibility.
  28. //
  29.  
  30. global proc showChannelBox(int $show)
  31. //
  32. //    Description:
  33. //
  34. //        *** Obsolete ***
  35. //
  36. //        *** Use runTimeCommand ToggleChannelsLayers instead ***
  37. //    
  38. //    Arguments:
  39. //        show - True if the Channel Box should be shown, false if the Channel
  40. //               Box should become hidden.
  41. //
  42. {
  43.     warning -showLineNumber true
  44.         ("The procedure \"showChannelBox()\" is now obsolete. "
  45.         + "Use the command \"ToggleChannelsLayers\" instead.");
  46. }
  47.  
  48. global proc int channelBoxVisibilityStateChange(
  49.     int    $newState,
  50.     string $layout)
  51. //
  52. //    Description:
  53. //        This procedure is called whenever the visibility state of the 
  54. //        Channel Box is changed.
  55. //
  56. //    Arguments:
  57. //        newState - The new visibile state of the Channel Box.
  58. //
  59. //        layout - The parent layout for the Channel Box.
  60. //
  61. //    Returns:
  62. //        true - If the change of state is to be allowed.
  63. //
  64. //        false - If the state change is rejected.
  65. //
  66. {
  67.     int $result = true;
  68.  
  69.     //    Defer these commands because this proc is called when the visibility
  70.     //    state is about to change. This proc must return true to accept 
  71.     //    the state change. After this proc returns then restore the
  72.     //    panel focus and update the pref menu.
  73.     //
  74.     evalDeferred("restoreLastPanelWithFocus(); updatePrefsMenu()");
  75.  
  76.     return $result;
  77. }
  78.  
  79. //  Procedure Name:
  80. //    checkSpeedButton
  81. //
  82. //  Description Name;
  83. //    Sets the button which visualizes the current speed which is
  84. //    used for channel box sliders
  85. //
  86. //  Input Value:
  87. //    which speed is currently set 
  88. //
  89. //  Output Value:
  90. //    None
  91. // 
  92. global proc checkSpeedButton ( string $speed, int $useManips )
  93. {
  94.     switch ($speed){
  95.         case "slow":
  96.             channelBox -e -speed 0.1 mainChannelBox;
  97.             symbolButton -e 
  98.                 -i "channelBoxSlow.xpm"
  99.                  -c ("channelBoxSettings medium " + $useManips )
  100.                 cbSpeedButton;
  101.             break;
  102.         case "medium":
  103.             channelBox -e -speed 1 mainChannelBox;
  104.             symbolButton -e 
  105.                 -i "channelBoxMedium.xpm"
  106.                  -c ("channelBoxSettings fast " + $useManips )
  107.                 cbSpeedButton;
  108.             break;
  109.         case "fast":
  110.             channelBox -e -speed 10 mainChannelBox;
  111.             symbolButton -e 
  112.                 -i "channelBoxFast.xpm"
  113.                  -c ("channelBoxSettings slow " + $useManips )
  114.                 cbSpeedButton;
  115.             break;
  116.         default:
  117.             symbolButton -e 
  118.                 -i "channelBoxUnknownSpeed.xpm"
  119.                  -c ("channelBoxSettings medium " + $useManips )
  120.                 cbSpeedButton;
  121.             break;
  122.             
  123.     }
  124. }
  125.  
  126.  
  127. //  Procedure Name:
  128. //    checkManipButton
  129. //
  130. //  Description Name;
  131. //    Sets the button which visualize which manipType is
  132. //    used in the channel box.
  133. //
  134. //  Input Value:
  135. //    which manipType is currently used 
  136. //
  137. //  Output Value:
  138. //    None
  139. // 
  140.  
  141.  
  142.  
  143. global proc checkManipButton ( int $state )
  144. {
  145.     switch ($state){
  146.         case 0:
  147.             symbolButton -e -i "channelBoxNoManips.xpm"
  148.                  -c "channelBoxSettings useManips 1"
  149.                 cbManipsButton;
  150.             break;
  151.         case 1:
  152.             symbolButton -e -i "channelBoxInvisibleManips.xpm"
  153.                  -c "channelBoxSettings useManips 2"
  154.                 cbManipsButton;
  155.             break;
  156.         case 2:
  157.             symbolButton -e -i "channelBoxUseManips.xpm"
  158.                  -c "channelBoxSettings useManips 0"
  159.                 cbManipsButton;
  160.             break;
  161.     }
  162. }
  163.  
  164. //
  165. //  Procedure Name:
  166. //      setChannelLongName
  167. //
  168. //  Description:
  169. //        Sets the Channel box long/short name flag and also changes the
  170. //        width of the Channel box and sets the optionVar for this setting.
  171. //
  172. //  Input Arguments:
  173. //      state - 0 = short, 1 = nice, 2 = long
  174. //
  175. //  Return Value:
  176. //      None.
  177. //
  178. global proc setChannelLongName( int $state )
  179. {
  180.     global string    $gChannelBoxName;
  181.     global int        $gChannelsLayersWidth;
  182.  
  183.     int $width;
  184.  
  185.     //    Query the current "name" state of the Channel box.
  186.     //
  187.     int $longNames = `channelBox -query -longNames $gChannelBoxName`;
  188.     int $niceNames = `channelBox -query -niceNames $gChannelBoxName`;
  189.  
  190.     //    Check for a change.
  191.     //
  192.     if ($niceNames && $state == 1) return;
  193.     if (!$niceNames && $longNames && $state == 2) return;
  194.     if (!$niceNames && !$longNames && $state == 0) return;
  195.  
  196.     if( $state == 2 ) {
  197.         $width = 180;
  198.         channelBox -e -ln true -nn false $gChannelBoxName;
  199.         optionVar -iv channelsLongName 2;
  200.  
  201.     } else if( $state == 1 ) {
  202.         $width = 140;
  203.         channelBox -e -ln true -nn true $gChannelBoxName;
  204.         optionVar -iv channelsLongName 1;
  205.  
  206.     } else {
  207.         $width = 140;
  208.         channelBox -e -ln false -nn false $gChannelBoxName;
  209.         optionVar -iv channelsLongName 0;
  210.     }
  211.  
  212.     setChannelsLayersWidth($width);
  213. }
  214.  
  215. global proc initChannelBoxButtons()
  216. //
  217. //    Handle initializing the icons at the top of the channel box
  218. //
  219. {
  220.     //    Get the current channel box settings to set
  221.     //    the buttons at the top of the channelbox to
  222.     //    the appropriate values
  223.     //
  224.     string $manipType = `channelBox -q -useManips mainChannelBox`;
  225.     int $useManips;
  226.     switch ($manipType){
  227.       case "none":
  228.         $useManips = 0;
  229.         break;
  230.       case "invisible":
  231.         $useManips = 1;
  232.         break;
  233.       default:
  234.         $useManips = 2;
  235.         break;
  236.     }
  237.     float $speed = `channelBox -q -speed mainChannelBox`;
  238.     string $speedMode;
  239.     if ($speed == 0.1) {
  240.         $speedMode = "slow";
  241.     } else if ($speed == 1.0) {
  242.         $speedMode = "medium";
  243.     } else if ($speed == 10.0) {
  244.         $speedMode = "fast";
  245.     } else {
  246.         $speedMode = "unknown";
  247.     }
  248.         
  249.     int $hyperbolic = `channelBox -q -hyperbolic mainChannelBox`;
  250.  
  251.     //    Update the buttons
  252.     //
  253.     symbolButton -edit
  254.         -enable true
  255.         cbManipsButton;
  256.     checkManipButton ($useManips);
  257.  
  258.     symbolButton -edit
  259.         -enable ( $useManips == 1 )
  260.         cbSpeedButton;
  261.     checkSpeedButton $speedMode $useManips;
  262.  
  263.     symbolCheckBox -edit
  264.         -v $hyperbolic
  265.         -enable ( $useManips == 1 )
  266.         cbHyperbolicButton;
  267. }
  268.  
  269. global proc channelBoxSettings( string $cmd, int $state )
  270. //
  271. //    Handle updating the icons at the top of the channel
  272. //    box when menu entries are selected in the popup menu
  273. {
  274.     switch( $cmd ) {
  275.         case "slow":
  276.             checkSpeedButton "slow" $state;
  277.             break;
  278.         case "medium":
  279.             checkSpeedButton "medium" $state;
  280.             break;
  281.         case "fast":
  282.             checkSpeedButton "fast" $state;
  283.             break;
  284.         case "hyperbolic":
  285.             channelBox -e -hyperbolic $state mainChannelBox;
  286.             symbolCheckBox -e -v $state cbHyperbolicButton;
  287.             break;
  288.         case "useManips":
  289.             checkManipButton ($state);
  290.  
  291.             if ( $state == 0 ) {
  292.                 //
  293.                 //    Manips are off - disable the speed settings
  294.                 //
  295.                 symbolButton -e -enable false cbSpeedButton;
  296.                 symbolCheckBox -e -enable false cbHyperbolicButton;
  297.                 channelBox -e -useManips "none" mainChannelBox;
  298.  
  299.             } else if( $state == 1 ) {
  300.                 //
  301.                 //    Manips are invisible only - enable the speed settings
  302.                 //
  303.                 symbolButton -e -enable true cbSpeedButton;
  304.                 symbolCheckBox -e -enable true cbHyperbolicButton;
  305.                 channelBox -e -useManips "invisible" mainChannelBox;
  306.  
  307.             } else {
  308.                 //
  309.                 //    Manips are standard - disable the speed settings
  310.                 //
  311.                 symbolButton -e -enable false cbSpeedButton;
  312.                 symbolCheckBox -e -enable false cbHyperbolicButton;
  313.                 channelBox -e -useManips "standard" mainChannelBox;
  314.             }
  315.             break;
  316.     }
  317. }
  318.  
  319. global proc buildChannelObjectMenu( string $parent ) {
  320. //
  321. //    Builds a menu with the last 20 items on the selection
  322. //    list, and allows the user to switch which objects
  323. //    values are being shown.  In effect, it switches
  324. //    the lead object, by "adding" it to the selection
  325. //    list, which places it last in the selection list
  326. //
  327.     setParent -m $parent;
  328.     menu -e -dai $parent;
  329.     int $size;
  330.             
  331.     string $sel[] = `ls -sl -tail 10`;
  332.     $size = `size( $sel )`;
  333.  
  334.     if( `isTrue SomethingSelected` ) {
  335.         menuItem -l $sel[ $size-1 ] -c ( "select -add " + $sel[ $size-1 ]);
  336.         menuItem -ob true -c ( "select -add "+$sel[$size-1]+"; editSelected" );
  337.         menuItem -d true;
  338.  
  339.         for($i = $size-2; $i >= 0; $i--) {
  340.             menuItem -l $sel[ $i ] -c ( "select -add " + $sel[ $i ] );
  341.             menuItem -ob true -c ( "select -add "+$sel[$i]+"; editSelected" );
  342.         }
  343.     } else {
  344.         menuItem -l "Nothing selected";
  345.     }
  346. }
  347.  
  348. // Now, the main script to be executed.  Not that this is NOT a proc.
  349. //
  350. {
  351.     //   Declare referenced or returned globals.
  352.     //
  353.     global string $gChannelBoxName;
  354.     global string $gChannelBoxForm;
  355.  
  356.     //  Determine values of option variables
  357.     //
  358.     int $channelsLongName = `optionVar -query channelsLongName`;
  359.     int $precision = `optionVar -q channelsPrecision`;
  360.     int $numWidth = `optionVar -q channelsFieldWidth`;
  361.  
  362.     //    Create a menu bar layout for the Channel box.
  363.     //
  364.     string $menuBarLayout = `menuBarLayout`;
  365.  
  366.     string $columnName;
  367.     int $nSections;
  368.  
  369.     // Add a menu to the menuBarLayout at the top of the
  370.     // channel box.  NOTE: can't make this menu a tearoff,
  371.     // as it dynamically updates based on channels selected
  372.     // in the channel box.
  373.     //
  374.     string $menu = `menu -label "Channels"
  375.                 -familyImage "menuIconChannels.xpm"`;
  376.         menu -edit -pmc ("generateChannelMenu " + $menu + " 0" ) $menu;
  377.     setParent -m ..;
  378.  
  379.     $menu = `menu -l "Object" 
  380.         -aob true
  381.         -familyImage "menuIconObject.xpm"`;
  382.         menu -e -pmc ( "buildChannelObjectMenu " + $menu ) $menu;
  383.     setParent -m ..;
  384.  
  385.     //  Build the Channel box, with a frame layout around it.
  386.     //
  387.     string $boxName = `frameLayout 
  388.         -labelVisible  false
  389.         -collapsable   false
  390.         -collapse      false 
  391.         -marginHeight  1
  392.         -marginWidth   1
  393.         -borderStyle   "etchedIn"`;
  394.  
  395.     //    Create the Channel box.
  396.     //
  397.     $gChannelBoxName = `channelBox -st true
  398.         -longNames ($channelsLongName==2)
  399.         -niceNames ($channelsLongName==1)
  400.         -precision $precision
  401.         -fieldWidth $numWidth
  402.         mainChannelBox`;
  403.  
  404.     //  Add the same menu that is in the menuBarLayout as a popup for the
  405.     //    whole channel box.
  406.     //
  407.     $menu = `popupMenu -parent $gChannelBoxName`;
  408.     menu -edit -postMenuCommand ( "generateChannelMenu " + $menu + " 1" ) $menu;
  409.  
  410.     setParent ..;
  411.  
  412.     //    Layout the separator, Channel box and the buttons.
  413.     //
  414.     formLayout -edit
  415.         -attachForm    $menuBarLayout "top"    0
  416.         -attachForm    $menuBarLayout "left"   0
  417.         -attachForm       $menuBarLayout "bottom" 0 
  418.         -attachForm    $menuBarLayout "right"  0
  419.         $gChannelBoxForm;
  420.  
  421.     initChannelBoxButtons();
  422. }
  423.  
  424.